import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * @date: 2018-09-24

 */
import { queryMapIdpValue } from 'cpaas-front/lib//services/api';
import { getResponse, createPagination } from 'utils/utils';
import { queryFileList as _queryFileList, addConfigDetail as _addConfigDetail, editConfigDetail as _editConfigDetail, deleteConfigDetail as _deleteConfigDetail, saveHeader as _saveHeader, getUploadDetail as _getUploadDetail } from "../services/fileUploadService";
export default {
  namespace: 'fileUpload',
  state: {
    fileData: {},
    // 文件列表
    fileTypeList: [],
    // 文件类型
    fileFormatsList: [],
    // 文件格式
    fileUnitList: [],
    // 单位
    pagination: {},
    // 分页信息
    fileDetail: {} // 详情数据

  },
  effects: {
    // 获取初始化数据
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_ref, _ref2) {
      var payload, call, put, lovCodes, res, fileTypeList, fileFormatsList, fileUnitList;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              lovCodes = payload.lovCodes;
              _context.t0 = getResponse;
              _context.next = 6;
              return call(queryMapIdpValue, lovCodes);

            case 6:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);

              if (!res) {
                _context.next = 12;
                break;
              }

              fileTypeList = res.fileTypeList, fileFormatsList = res.fileFormatsList, fileUnitList = res.fileUnitList;
              _context.next = 12;
              return put({
                type: 'updateState',
                payload: {
                  fileTypeList: fileTypeList,
                  fileFormatsList: fileFormatsList,
                  fileUnitList: fileUnitList
                }
              });

            case 12:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    // 获取文件列表
    queryFileList: /*#__PURE__*/_regeneratorRuntime.mark(function queryFileList(_ref3, _ref4) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function queryFileList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              _context2.next = 4;
              return call(_queryFileList, payload);

            case 4:
              res = _context2.sent;
              list = getResponse(res);

              if (!list) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  fileData: list,
                  pagination: createPagination(list.listConfig)
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, queryFileList);
    }),
    // 获取文件上传详情
    getUploadDetail: /*#__PURE__*/_regeneratorRuntime.mark(function getUploadDetail(_ref5, _ref6) {
      var payload, call, put, res, data;
      return _regeneratorRuntime.wrap(function getUploadDetail$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call, put = _ref6.put;
              _context3.next = 4;
              return call(_getUploadDetail, payload);

            case 4:
              res = _context3.sent;
              data = getResponse(res);

              if (!data) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  fileDetail: data
                }
              });

            case 9:
              return _context3.abrupt("return", data);

            case 10:
            case "end":
              return _context3.stop();
          }
        }
      }, getUploadDetail);
    }),
    // 新增保存
    addConfigDetail: /*#__PURE__*/_regeneratorRuntime.mark(function addConfigDetail(_ref7, _ref8) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function addConfigDetail$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(_addConfigDetail, _objectSpread({}, payload));

            case 4:
              result = _context4.sent;
              return _context4.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, addConfigDetail);
    }),
    // 编辑保存
    editConfigDetail: /*#__PURE__*/_regeneratorRuntime.mark(function editConfigDetail(_ref9, _ref10) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function editConfigDetail$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call;
              _context5.next = 4;
              return call(_editConfigDetail, _objectSpread({}, payload));

            case 4:
              result = _context5.sent;
              return _context5.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, editConfigDetail);
    }),
    // 删除
    deleteConfigDetail: /*#__PURE__*/_regeneratorRuntime.mark(function deleteConfigDetail(_ref11, _ref12) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function deleteConfigDetail$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call;
              _context6.next = 4;
              return call(_deleteConfigDetail, payload);

            case 4:
              result = _context6.sent;
              return _context6.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, deleteConfigDetail);
    }),
    // 保存头
    saveHeader: /*#__PURE__*/_regeneratorRuntime.mark(function saveHeader(_ref13, _ref14) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function saveHeader$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref13.payload;
              call = _ref14.call;
              _context7.next = 4;
              return call(_saveHeader, _objectSpread({}, payload));

            case 4:
              result = _context7.sent;
              return _context7.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, saveHeader);
    })
  },
  reducers: {
    updateState: function updateState(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    }
  }
};